#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>
#include<time.h>

void CreateNDate()
{
    int n = 100000;
    srand((time(0)));
    char* file = "data.txt";
    FILE* fin = fopen(file, "w");
    if (fin == NULL)
    {
        perror("fopen error!\n");
        exit(1);
    }
    for (int i = 0; i < n; i++)
    {
        int x = (rand() + i) % 1000000;
        fprintf(fin, "%d\n", x);
    }
    fclose(fin);
}

void AdjustDown(int* arr, int parent, int n)
{
    int child = parent * 2 + 1;
    while (child < n)
    {
        if (child + 1 < n && arr[child] < arr[child + 1])
        {
            child++;
        }
        if (arr[child] > arr[parent])
        {
            int temp = arr[child];
            arr[child] = arr[parent];
            arr[parent] = temp;
            parent = child;
            child = parent * 2 + 1;
        }
        else
            break;
    }
}

void TopK()
{
    int k = 0;
    scanf("%d", &k);
    FILE* fout = fopen("data.txt", "r");
    if (fout == NULL)
    {
        perror("fopen error!\n");
        exit(1);
    }
    int* MinHeap = (int*)malloc(sizeof(int) * k);
    if (MinHeap == NULL)
    {
        perror("malloc fail!\n");
        exit(2);
    }
    for (int i = 0; i < k; i++)
    {
        fscanf(fout, "%d", &MinHeap[i]);
    }
    for (int i = (k - 1 - 1) / 2; i >= 0; i--)
    {
        AdjustDown(MinHeap, i, k);
    }
    int x = 0;
    while (fscanf(fout, "%d", &x) != EOF)
    {
        if (x < MinHeap[0])
        {
            MinHeap[0] = x;
        }
        AdjustDown(MinHeap, 0, k);
    }
    for (int i = 0; i < k; i++)
    {
        printf("%d ", MinHeap[i]);
    }
}

int main()
{
    //CreateNDate();
    TopK();
    return 0;
}